<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/tiles2/common.jsp" %>
<c:set var="b" value="${board}" />    
<div class="page-header">
	<h3 class="font24">Q & A</h3>
</div>
<article>
	<div class="row">
		<div class="span5 offset1">
			<a class="btn" id="prevbtn"><i class="icon-chevron-left"></i>&nbsp;이전게시물</a>
			<a class="btn" id="nextbtn"><i class="icon-chevron-right"></i>&nbsp;다음게시물</a>
		</div>
		<div class="span5 tright">
		<a class="btn" id="newbtn"><i class="icon-plus-sign"></i>&nbsp;		새글쓰기</a></div>
	</div>
	
	<div class="row">
		<div class="span10 offset1">
			<table class="table linetopdown topmargin">
				<caption class="caption">${b.title}</caption>
				<tbody>
					<tr class="vheader"><td>${b.uid}</td>
					<td class="vfooter" style="text-align: right">${b.regdate}/${b.goods}/${b.reades}</td>					</tr>
					<tr><td colspan="2" class="vbody">${b.contents}</td></tr>					
				</tbody>
			</table>
		</div>
	</div>
	
	<div class="row">
		<div class="span5 offset1"><a class="btn btn-warning" id="updatebtn">	<i class="icon-question-sign icon-white">
			</i>&nbsp;수정하기</a>
			<a class="btn btn-danger" id="deletebtn">
			<i class="icon-remove-sign icon-white">
			</i>&nbsp;삭제하기</a>
		</div>
		<div class="span5 tright">
		<a class="btn" id="listbtn"><i class="icon-list"></i>&nbsp;
		목록으로</a></div>
	</div>

	<div class="row topmargin">
		<div class="span10 offset1">
			<div><img class="fleft titlelogo"
			src="img/ext/glyphicons_309_comments.png">
			<h3>나도 한마디</h3></div>
			<table class="table linetopdown">
			<c:forEach var="c" items="${comments}">
				<c:if test="${c.cno eq c.rno}">
					<tr>
						<td style="width:20%">${c.uid}</td>
						<td colspan="2">
							<p class="replyhdr1">${c.regdate}<span class="fright">
							<a onclick="sendReply(${c.cno})">[리플추가]</a></span></p>
							<p>${c.comments}</p>
						</td>
					</tr>
				</c:if>
				<c:if test="${c.cno ne c.rno }" >
					<tr>
						<td style="width:20%">&nbsp;</td>
						<td colspan="2">
							<p class="replyhdr2">${c.uid}<span class="fright">
							${c.regdate}</span></p>
							<p>${c.comments}</p>
						</td>
					</tr>
				</c:if>
			</c:forEach>
			</table>
		</div>
	</div>
	
	<div class="row topmargin">
		<div class="span10 offset1">
			<form id="comntfrm"	
			class="well form-inline">
				<fieldset class="control-group info">
					<label>로그인하세요</label>
					<textarea rows="5" class="span7"
					name="comments" id="comments"></textarea>
					<a class="btn" id="comntbtn">댓글쓰기</a>
				</fieldset>
				<input type="hidden" name="uid"
					value="noName" />
				<%-- <input type="hidden" name="bno"
					value="${b.bno}" /> --%>
			</form>
		</div>
	</div>
	
	<!-- 리플 입력폼 -->
	<div class="modal replywidth hide" id="replyModal">
		<form id="replyfrm" class="well form-inline">
			<fieldset class="control-group error">
				<label>noNameX</label>
				<textarea rows="8" class="span5"
				name="reply" id="reply"></textarea>
				<a id="replybtn" class="btn">리플작성</a>
				<input type="hidden" name="uid" value="noNameX" />
				<input type="hidden" name="rno" id="rno" />
				<input type="hidden" name="bno"
					value="${param.bno}" />	
			</fieldset>			
		</form>
	</div>

</article>

<script>
	$("#newbtn").on("click", function(event) {
		$(location).attr("href",
						"<c:url value='/board/write.mvc'/>");	
	});
	
	$("#listbtn").on("click", function(event) {
		$(location).attr("href",
		"<c:url value='/board/list.mvc'/>");
	});
	$("#prevbtn").on("click", function(event) {});
	$("#nextbtn").on("click", function(event) {});
	
	$("#updatebtn").on("click", function(event) {
		$(location).attr("href",
		"<c:url value='/board/write.mvc'/>");
	});
	$("#deletebtn").on("click", function(event) {
		if (confirm("정말로, 진짜로, 사실로, 참말로?"))
			$(location).attr("href", 
					"<c:url value='/board/deleteok.mvc'/>");		
	});
	$("#comntbtn").on("click", function(event) {
		if ($("#comments").val() == "") alert();
		else
			$("#comntfrm").attr("method","post")
			.submit();		
	});
	$("#replybtn").on("click", function(event) {
		if ($("#reply").val() == "") alert();
		else 
			$("#replyfrm").attr("method", "post")
			.attr("action", 
					"<c:url value='/board/reply.mvc'/>")
			.submit();
	});
</script>
<script>
	function sendReply(cno) {
		$("#replyModal").modal('show');
		$("#rno").val( cno );
	};
</script>












